//
//  MessageDetailCell.m
//  WGFGlobalHouses
//
//  Created by waiguofang on 15/7/10.
//  Copyright (c) 2015年 waiguofang. All rights reserved.
//

#import "MessageDetailCell.h"
#import "StringTool.h"
#import "NSString+category.h"
#import "UIImage+Category.h"
#import "config.h"



@interface MessageDetailCell()
@property (weak, nonatomic) IBOutlet UIImageView *image;
@property (weak, nonatomic) IBOutlet UILabel *messageDate;
@property (weak, nonatomic) IBOutlet UILabel *detailLab;

@property (weak, nonatomic) IBOutlet UIButton *bgBtn;


@end

@implementation MessageDetailCell


+(instancetype)cellWithTableView:(UITableView *)tableView {
    
    static NSString *ID = @"MessageDetailCell";
    MessageDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (!cell) {
        
        cell = [[[NSBundle mainBundle]loadNibNamed:@"MessageDetailCell" owner:nil options:nil]lastObject];
        
        [cell.messageDate.layer setMasksToBounds:YES];
        [cell.messageDate.layer setCornerRadius:5];
        
        cell.detailLab.preferredMaxLayoutWidth = PMW  -10-40-10-10-20;
        [cell.detailLab layoutIfNeeded];
        
        [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    }
    
    return cell;
}

+(CGFloat)getHeightWithTableView:(UITableView *)tableView  Model:(MessageModel *)model{
    
    static MessageDetailCell *cell = nil;
    
    static dispatch_once_t predicate;
    dispatch_once(&predicate, ^{
        
        cell = [MessageDetailCell cellWithTableView:tableView];
    });
    
    [cell setModel:model ];
    
    CGFloat height = [cell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
    
    return height > 80? height:80;
}

-(void)setModel:(MessageModel *)model{
    
    
    if (![StringTool isBlankString:model.messageTime]) {
        
        self.messageDate.text = model.messageTime;
    }
    
    if (![StringTool isBlankString:model.messageSub]) {
        
        [self.detailLab setText:model.messageSub];;
    }
    
    if (model.messageType ==MessageTypeSYS) {
        
        [self.image setImage:[UIImage imageNamed:@"message14"]];
        
    }else if (model.messageType ==MessageTypeACTIVITY){
        
        [self.image setImage:[UIImage imageNamed:@"message15"]];
        
    }else if (model.messageType ==MessageTypeORDER){
        
        [self.image setImage:[UIImage imageNamed:@"message16"]];
    }
    
    UIImage *bgImg = [UIImage imageNamed:@"xiaoxinbg"];
    bgImg = [bgImg stretchableImageWithLeftCapWidth:bgImg.size.width*0.5 topCapHeight:bgImg.size.height*0.5];
    
    [self.bgBtn setBackgroundImage:bgImg forState:UIControlStateNormal];
    
}
@end
